use Test;

### Creation Test:
### ==============
## Create a class and verify success
## Meant to be used as the first dependency of other tests

## Includes the required module for the class
##   If one is set in the container, it is used instead of the class name
## Verifies that an object is created
## Verifies that actual type is correct

## Leaves the created object in the container for further use

package CreationTest;
## Keys for accessing the container:
#-----------------------------------
# TESTED_CLASS: Name of the class wich creation is to be tested
# TESTED_CLASS_CONSTRUCTOR: Name of the creation subroutine in the tested class
# TESTED_OBJ: Actual created object under test
# TESTED_MODULE: Fully qualified name of the module where the tested class belongs

@ISA = qw/Test/;

sub init{
    my $self = shift;
}

sub setup{
    my $self = shift;
    
 }

sub run{
    my $self = shift;
    my ($type, $constructor, $module) = ($self->component(TESTED_CLASS), $self->component(TESTED_CLASS_CONSTRUCTOR), $self->component(TESTED_MODULE));

    $module = $type if($module eq ""); # Module defaults to class name

    # Include the necessary class
    $self->log("Including module: ".$module);
    $self->evaluate("use ".$module);

    # Create the object
    $self->log("Creating object");
    my $creationCode = $type."->".$constructor."()";
    my $obj = $self->evaluate($creationCode);

    # Check if result is a defined value
    $self->assertNEq($obj, undef, "OBJ_IS_DEFINED", "CRITICAL");

    # Check if result is a correct reference
    $self->assertEq(ref $obj, $type, "OBJ_TYPE_CORRECT", "CRITICAL");

    
    # Fail if either of the above failed
    return if($self->{STATUS} eq "CRITICAL");

    # Check if all the expected fields are present
    # and are of the correct type
    for my $field (keys(%{$obj})){
	my $expectedType = "asda";
    } # for keys($obj)


    # Store the created object in the container
    $self->store("TESTED_OBJ", $obj);
}

sub teardown{
    my $self = shift;

}

1;
